package vip.mall.modular.uiapp.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import vip.mall.common.params.CommonPageParams;
import vip.mall.common.result.CommonPageResult;
import vip.mall.modular.uiapp.entity.Questions;
import vip.mall.modular.uiapp.mapper.QuestionsMapper;
import vip.mall.modular.uiapp.params.QuestionsAddParams;
import vip.mall.modular.uiapp.service.QuestionService;

/**
 * @author ASUS
 * @Date 2025/6/17 10:57
 * @Descripition
 */
@Service
public class QuestionServiceImpl extends ServiceImpl<QuestionsMapper, Questions> implements QuestionService {
    @Override
    public boolean add(QuestionsAddParams questionsAddParams) {
        Questions questions = BeanUtil.copyProperties(questionsAddParams, Questions.class);
        return this.save(questions);
    }

    @Override
    public CommonPageResult pageList(CommonPageParams commonPageParams) {
        Page<Questions> page=new Page<>(commonPageParams.getPageNum(),commonPageParams.getPageSize());
        Page<Questions> questionsPage = this.page(page);
        if (ObjectUtil.isNotNull(questionsPage)) {
            return CommonPageResult.builder()
                    .data(questionsPage.getRecords())
                    .pageNum((int) questionsPage.getCurrent())
                    .pageSize((int) questionsPage.getSize())
                    .total(questionsPage.getTotal())
                    .totalPage((int) questionsPage.getPages())
                    .build();
        }
        return null;
    }
}
